package com.qysoft.dtkj.dtkj_gl.services.cjgl;

import java.util.HashMap;

import com.qysoft.rapid.dao.mybatis.RapidDao;
import com.qysoft.rapid.domain.Bean;
import com.qysoft.rapid.exceptions.BizException;

public class CJGLService {

	/**
	 * 保存url采集信息
	 * @param parameters
	 * @throws Exception
	 */
	public static void saveCJXX(HashMap<String, Object> parameters) throws Exception{
		//保存url信息
		RapidDao.insertByXml("capinfo_insert", parameters);
	}
	
	/**
	 * 修改url采集状态
	 * @param isCap
	 * @param urlId
	 * @throws Exception
	 */
	public static void updateIsCap(String isCap,String capId) throws Exception{
		String updateSql = "update dtkj_capinfo t set t.iscap = ? where capid = ?";
		RapidDao.executeSql(updateSql, isCap,capId);
	}
	
	/**
	 * 删除url采集信息
	 * @param urlId
	 * @throws Exception
	 */
	public static void deleteCJXX(String capId) throws Exception{
		String deleteSql = "delete from dtkj_capinfo t where t.capid = ?";
		RapidDao.executeSql(deleteSql, capId);
	}

	/**
	 * 根据id获取一条税源企业信息
	 * @param qyid
	 * @return
	 */
	public static Bean querySyqy(long qyid) throws Exception {
		Bean qyxx = RapidDao.selectOneByXml("querySyqyxx", qyid);
		return qyxx;
	}

	/**
	 * 添加税源企业信息
	 * @param qyxx
	 * @throws Exception
	 */
	public static void addSyqy(Bean qyxx) throws Exception {
		int count = RapidDao.selectOneByXml("queryCountByQymcAndQyjc", qyxx);
		if (count > 0) {
			throw new BizException("企业名称或简称重复，请重新输入！");
		}
		
		// 获取qyid
		long qyid = RapidDao.selectOneByXml("querySyqyIdForAdd");
		qyxx.set("qyid", qyid);
		
		// 执行保存
		RapidDao.insertByXml("addSyqyxx", qyxx);
	}

	/**
	 * 修改税源企业信息
	 * @param qyxx
	 * @throws Exception 
	 */
	public static void updateSyqy(Bean qyxx) throws Exception {
		int count = RapidDao.selectOneByXml("queryCountByQymcAndQyjcForUpd", qyxx);
		if (count > 0) {
			throw new BizException("企业名称或简称重复，请重新输入！");
		}
		RapidDao.updateByXml("updateSyqyxx", qyxx);
	}

	/**
	 * 删除税源企业信息
	 * @param qyid
	 * @throws Exception 
	 */
	public static void deleteSyqyxx(long qyid) throws Exception {
		RapidDao.deleteById("DTKJ_QYXX", "QYID", qyid);
	}
	
}
